﻿using Microsoft.Data.ConnectionUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeBuilder
{
    public class MySqlConnectionProperties : AdoDotNetConnectionProperties
    {
        private const int SqlError_CannotOpenDatabase = 4060;

        public override bool IsComplete
        {
            get
            {
                if (!(base.ConnectionStringBuilder["Server"] is string) || (base.ConnectionStringBuilder["Server"] as string).Length == 0)
                {
                    return false;
                }
                string value = this.ConnectionStringBuilder["Database"] as string;
                if (string.IsNullOrEmpty(value))
                {
                    return false;
                }
                return (bool)(base.ConnectionStringBuilder["User ID"] is string && (base.ConnectionStringBuilder["User ID"] as string).Length != 0);
            }
        }


        protected override PropertyDescriptor DefaultProperty
        {
            get
            {
                return this.GetProperties(new Attribute[0])["DataSource"];
            }
        }

        public MySqlConnectionProperties() : base("MySql.Data.MySqlClient")
        {

        }

        protected override void OnPropertyChanged(EventArgs e)
        {
            base.OnPropertyChanged(e);
        }

        public override void Reset()
        {
            base.Reset();
        }

        public override void Test()
        {
            string text = base.ConnectionStringBuilder["Data Source"] as string;
            if (text == null || text.Length == 0)
            {
                throw new InvalidOperationException(("SqlConnectionProperties_MustSpecifyDataSource"));
            }
            if (SqlFileVersionCheckHelper.IsVersionCheckEnabled)
            {
                SqlFileVersionCheckHelper.CheckIfDatabaseFileVersionIsLowerThanSpecifiedInstance(base.ConnectionStringBuilder.ToString());
            }
            string text2 = base.ConnectionStringBuilder["Initial Catalog"] as string;
            try
            {
                base.Test();
            }
            catch (MySql.Data.MySqlClient.MySqlException arg_66_0)
            {
                if (arg_66_0.Number == 4060 && text2 != null && text2.Length > 0)
                {
                    throw new InvalidOperationException(("SqlConnectionProperties_CannotTestNonExistentDatabase"));
                }
                throw;
            }
        }
    }
}
